/*
 */
package com.ericsson.springintegrationtest.controller;

import com.ericsson.springintegrationtest.model.User;
import com.ericsson.springintegrationtest.service.UserService;
import java.util.logging.Level;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.Message;
import org.springframework.integration.core.MessageSelector;

/**
 *
 * @author eluibon
 */
public class UserCheck implements MessageSelector {
    
    protected Logger log = Logger.getLogger(this.getClass().getName());
    
    @Autowired
    UserService userService ;

    @Override
    public boolean accept(Message<?> msg) {
        
        User user  = (User)msg.getPayload();       
        try {
            Thread.sleep(1000);
        }
        catch (InterruptedException ex) {
            java.util.logging.Logger.getLogger(UserCheck.class.getName()).log(Level.SEVERE, null, ex);
        }
        return userService.findByName(user.getFirstName(), user.getLastName()) == null ;
    }
}
